package control;
/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
//package Server;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;
import service.*;

/**
 *
 * @author Islam
 */
public class SessionImp extends UnicastRemoteObject implements SessionInt {

    private ArrayList<ChatRoomInt> chatRooms = new ArrayList<>();
    private static List<SessionInt> sessions = new ArrayList<>();
    private ServerController serverController;
    private String email;
    private String name;

    public SessionImp(String email) throws RemoteException {
        this.email = email;
        System.out.println("Hello, " + this.email + " i'm pleased to be your new session ");
    }

    @Override
    public void addChatRoom(ChatRoomInt room) throws RemoteException {
        getChatRooms().add(room);
    }

    @Override
    public ChatRoomInt makeNewRoom() throws RemoteException {
        return new ChatRoomImp();
    }

    @Override
    public void removeChatRoom(int ID) throws RemoteException {

        getChatRooms().remove(ID);
    }

    @Override
    public ChatRoomInt getChatRoom(int ID) throws RemoteException {

        return getChatRooms().get(ID);
    }

    @Override
    public void logout() throws RemoteException {
        System.out.println("Bye Bye, " + this.getSessionEmail());
        serverController.logoutUpdateAdmin(getSessionEmail());
        unexportObject(this, true);
    }

    public void testExisting() throws RemoteException {
        System.out.println("I'm still running " + this.getSessionEmail());
    }

    public ArrayList<ChatRoomInt> getChatRooms() {
        return chatRooms;
    }

    public void setChatRooms(ArrayList<ChatRoomInt> chatRooms) {
        this.chatRooms = chatRooms;
    }

    /**
     * @return the sessions
     */
    public static List<SessionInt> getSessions() {
        return sessions;
    }

    /**
     * @return the sessionEmail
     */
    @Override
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static void setSessions(List<SessionInt> aSessions) {
        sessions = aSessions;
    }

    @Override
    public String getSessionEmail() throws RemoteException {
        return email;
    }

    @Override
    public void setSessionEmail(String sessionEmail) throws RemoteException {
        email = sessionEmail;
    }

    public void setServerController(ServerController serverController) {
        this.serverController = serverController;
    }
}
